/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maxent.mr.mapred;

import java.io.IOException;
import java.util.Iterator;
import maxent.mr.writable.FeatureKeyWritable;
import maxent.mr.writable.FeatureKeysWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

/**
 *
 * @author hadoop
 */
public class FeatureReducer
        extends Reducer<IntWritable, FeatureKeyWritable, IntWritable, FeatureKeysWritable>{

    @Override
    public void reduce(IntWritable key, Iterable<FeatureKeyWritable> values, Context context) throws IOException, InterruptedException{

        Iterator<FeatureKeyWritable> valueIt = values.iterator();
        FeatureKeysWritable fkWrite = new FeatureKeysWritable();

        while(valueIt.hasNext()){
            fkWrite.addFeature(valueIt.next());
        }

        context.write(key, fkWrite);
    }
}
